package cn.yanxiaohui.service.web.pattern.single;
/**
 * 单例模式
 * @author yanxh
 *
 */
public class SingleTemplate {
	private SingleTemplate() {}
	
	private static SingleTemplate single1 = null;
	
	private static SingleTemplate single2 = new SingleTemplate();
	
	/**
	 * 饿汉式
	 * @return
	 */
	public static SingleTemplate getInstance1() {
		return single2;
	}
	
	
	/**
	 * 懒汉式
	 * 	存在线程安全，不能保证单例
	 * @return
	 */
	public static SingleTemplate getInstance2() {
		if(single1 == null) {
			single1 = new SingleTemplate();	
		}
		return single1;
	}
}
